module ui {

    export class AdvancedScoreView extends egret.DisplayObjectContainer implements manager.ITick {

        public static readonly DT: number = 20;

        private dt: number = 0;

        private myScoreTxt: ImageNumber;

        private score: number = 0;

        private currentScore: number = 0;

        public constructor() {
            super();
            this.myScoreTxt = new ImageNumber(0, new GameSpriteSheet(manager.ResManager.getTexture("rthrtb_png")));
            this.addChild(this.myScoreTxt);
            this.initUI();
            manager.TickManager.getInstance().addTick(this);
        }

        public initUI() {
            this.reset();
        }

        public getScore(): number {
            return this.score;
        }

        public addScore(score: number): void {
            this.score += score;
        }

        public reset(): void {
            this.score = 0;
            this.currentScore = 0;
            this.render(this.score);
            this.setScore(0);
        }

        public onTick(dt: number): void {
            this.dt += dt;
            if (this.dt < AdvancedScoreView.DT) {
                return;
            }
            this.dt -= AdvancedScoreView.DT;
            if (this.currentScore < this.score) {
                this.currentScore += 1;
                this.render(this.currentScore);
            }
        }

        public render(score: number): void {
            this.myScoreTxt.setNb(score);
        }

        public setScore(score: number): void {
            this.score = score;
        }
    }
}